#include <iostream>
#include <conio.h>
#include "GameObject.h"
#include <time.h>
using namespace std;

#define WORLD_HEIGHT 22
#define WORLD_WIDTH 60
#define EMPTY ' '
int main()
{
	int a=(rand() % 60) + 1;
	int b=(rand() % 21 )+ 1;
	int c=(rand() % 60) + 1;
	int d=(rand() % 21 )+ 1;
	const int enemyCount=9;
	srand(time(NULL));
	char board[WORLD_HEIGHT][WORLD_WIDTH];
	GameObject player (5,5,5);
	GameObject coin(4,a,b);
	//GameObject enemy(1,c,d);
	GameObject enemy[enemyCount];
	bool quit =false;
	bool createEnemy=true;
	coin.score=false;
	int point=0;

	while(!quit)
	{
		for(int i=0;i<9;i++)
		{
			if(player.x==enemy[i].x && player.y==enemy[i].y)
	    	{
			system("cls");
			cout<<"\n\n\n ******************************** GAME OVER ******************************** \n";
			point=0;
			for(int i=0;i<9;i++)
			{
			c=(rand() % 60) + 1;
			d=(rand() % 21 )+ 1;
			enemy[i].setX(c);
			enemy[i].setY(d);
			enemy[i].sprite=1;
			}
			
			a=(rand() % 60 )+ 1;
			b=(rand() % 21 )+ 1;
			
			coin.setX(a);
			coin.setY(b);
			system("pause");
			}
		}
		system("cls");
		for(int y=0;y<WORLD_HEIGHT;y++)
		{
			for(int x=0;x<WORLD_WIDTH;x++)
			{
				board[y][x]= EMPTY;
			}
		}



		if(player.x==coin.x && player.y==coin.y)
		{
			coin.destroy();
		}
		
		if(coin.score)
		{

			a=(rand() % 60 )+ 1;
			b=(rand() % 21 )+ 1;
			coin.setX(a);
			coin.setY(b);
			point++;
			coin.score=false;

		}
		
		if(point>=5)
		{
			
		}
		
		cout<< point;
		for(int i=0;i<enemyCount;i++)
		{
			board[enemy[i].y][enemy[i].x]=enemy[i].getSprite();
		}
		board[coin.y][coin.x]=coin.getSprite();
		board[player.y][player.x]=player.getSprite();


		//drawing
		for(int y=0;y<WORLD_HEIGHT;y++)
		{
			for(int x=0;x<WORLD_WIDTH;x++)
			{
				cout<< board[y][x];
			}
			cout<<endl;
		}

		char input= _getch();
		switch(input)
		{	

		case 'w':
			player.y-=1;
			break;
		case 'a':
			player.x-=1;
			break;
		case 'd':
			player.x+=1;
			break;
		case 's':
			player.y+=1;
			break;
		case 'q':
			quit=true;
			break;
		}
		if(quit)
		{
			exit(1);
		}

	}

}